<template>
	<view >
		<input @blur="blurFun" v-model="nickName" type="nickname" class="weui-input" placeholder="请输入昵称"/>
	</view>
</template>

<script setup>
	import { ref , watch , defineEmits} from "vue"
	
	import MyInput from '@/components/MyInput/MyInput.vue'
	
	import {userStore} from '@/stores/user'
	
	import {UserModel} from '@/service/model/user.js'
	
	import {
		dynamicStyleStore
	} from '@/stores/dynamicStyle.js'
	
	const dynamicStyle_store = dynamicStyleStore()
	
	const {
		primary_cool_color,
		primary_text_color
	} = dynamicStyle_store.dormitoryStyle	
	
	const props=defineProps({
		clickSubmitNickNameFlag:{
			type:Number
		}
	})
	
	watch(()=>props.clickSubmitNickNameFlag,()=>{
		submitNickName()
	})
	
	const nickName = ref('')
	
	const user_store = userStore()
	
	const userModel = new UserModel()
	
	const blurFun=(e)=>{
		nickName.value=e.detail.value
	}
	
	
	//提交修改名字
	const submitNickName=async()=>{
		const {
			user_name,
			phone,
			sex,
			id,
			user_avatar
		} = user_store.userInfo
		
		if(!nickName.value.trim()){
			uni.$emit('tips','请输入有效的昵称!','warn')
			return
		}
		
		const {data,success} = await userModel.postUpdateUserInfo({
			user_name,
			phone:'15888888888',
			sex,
			nick_name:nickName.value,
			user_avatar
		},id)
		
		if(success){
			user_store.userInfo.nick_name = nickName.value
			nickName.value=''
			uni.$emit('tips',data+',如果想修改某宿舍下的昵称，请点击常用宿舍-宿舍设置-修改昵称','success',4000)
		}
	}
</script>

<style lang="less">
	.weui-input{
		color: v-bind(primary_text_color);
	}
</style>